package com.yiquan.search.controller;

import com.yiquan.search.entity.User;
import com.yiquan.search.entity.Video;
import com.yiquan.search.entity.vo.SearchUserPageVO;
import com.yiquan.search.entity.vo.SearchVideoPageVO;
import com.yiquan.search.service.SearchService;
import entity.Result;
import entity.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author xieyl
 * @create 2022/1/25 21:27
 */
@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 用户搜索
     * @param keyWord
     * @param userId
     * @return
     */
    @GetMapping("/user")
    public Result searchUser(@RequestParam String keyWord ,@RequestParam Long userId) {
        List<SearchUserPageVO> users = searchService.searchUser(keyWord,userId);
        return new Result(users);

    }

    /**
     * 视频搜索
     * @param keyWord
     * @return
     */
    @GetMapping("/video")
    public Result searchVideo(@RequestParam String keyWord){
        List<SearchVideoPageVO> videos = searchService.searchVideo(keyWord);
        return new Result(videos);
    }

    @GetMapping("/getHotSearch")
    public Result getHotSearchWord(){
        List<Map> hotSearchWordList = searchService.getHotSearchWord();
        return new Result(hotSearchWordList);
    }

    @GetMapping("/setHotSearchWord")
    public Result setHotSearchWord(@RequestParam String hotWord){
        searchService.setHotSearchWord(hotWord);
        return new Result(StatusCode.OK);
    }

    @GetMapping("/user/{page}")
    public Result searchUserNoEs(@RequestParam String keyWord,@PathVariable Integer page,@RequestParam Long userId){
        log.info("keyword:{},  userId:{},",keyWord,userId);
        return new Result(searchService.searchUserNoEs(keyWord,page,userId));
    }

}
